package com.gy.api.mobile.huasu.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson.JSON;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.HuaSuConstant;
import com.gy.api.base.R;
import com.gy.api.mobile.huasu.domain.CinemaOutVo;
import com.gy.api.mobile.huasu.domain.FilmManagmentDto;
import com.gy.util.HSClient;
import com.gy.util.ReflectionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DecimalFormat;
import java.util.List;


@RestController
@RequestMapping("/system/hs/film")
@RequiredArgsConstructor
@Api( tags = ApiIndex.H5_HuaSuController)
public class FilmManagementController {

    @Autowired
    private HSClient hsClient;

    @GetMapping("/management")
    @ApiOperation("影院管理-影院-外部推荐")
    public R<List<CinemaOutVo>> management(FilmManagmentDto dto) {
        String s = ReflectionUtil.convertEntityToQueryString(dto);
        String cinemaPrefix = HuaSuConstant.CINEMA_PREFIX;
        R request = hsClient.getRequest(cinemaPrefix, s, CinemaOutVo.class,StpUtil.getTokenValue());
        Object data = request.getData();
        String json = JSON.toJSONString(data);
        return new R(JSON.parseArray(json,CinemaOutVo.class));
    }


    public static void main(String[] args) {
        double num1 = 0;
        double num2 = 2;
        DecimalFormat decimalFormat = new DecimalFormat("#");
        double percentage = NumberUtil.div(NumberUtil.mul(num1, 100), num2);
        System.out.println("百分比为：" + decimalFormat.format(percentage) + "%");
    }



}
